#species_list includes Boarfish which doesn't have values, so add 'length()-1'
prey_type_list <- list("benthos", "fish", "nekton", "other", "zooplankton")
for (i in 1:(length(species_list)-1)){
b=f=n=o=z=0
name <- species_list[i]
first_species <- renamed_df %>% filter(renamed_df$pred_species == fixed(name))
for(i in 1:length(first_species)){
benthos <- first_species[first_species$prey_type == fixed("benthos"),]
b <- length(benthos$haul_id)
fish <- first_species[first_species$prey_type == fixed("fish"),]
f <- length(fish$haul_id)
nekton <- first_species[first_species$prey_type == fixed("nekton"),]
n <- length(nekton$haul_id)
other <- first_species[first_species$prey_type == fixed("other"),]
o <- length(other$haul_id)
zoo <- first_species[first_species$prey_type == fixed("zooplankton"),]
z <- length(zoo$haul_id)
}
x <- c(b,f,n,o,z)
pie(x, prey_type_list, main = name)
}
These are individual pie charts showing the distribution of the type of
prey each predator eats.
#Separated into individual plots for each predator species -> using facet_wrap for the variable (pred_species)
ggplot(data = renamed_df, aes(x=log(ppmr)), group=1) +
labs(title = "log(PPMR) v. biomass density of prey", x="log(PPMR)", y="Biomass density of prey") +
facet_wrap(~renamed_df$pred_species, scale="free_y") +
theme(strip.text = element_text(size = 5)) +
geom_density(aes(weight = prey_weight_g), colour="red")
#poor cod and boarfish?
for (i in 1:length(species_list)){
name <- species_list[i]
first_species <- renamed_df %>%
filter(pred_species == fixed(name))
ggplot(data = first_species, aes(x=log(ppmr)), group=1) +
labs(title = name, x="log(PPMR)", y="biomass density of prey") +
geom_density(aes(weight = prey_weight_g), colour="red") +
theme(plot.title = element_text(size=15))
av <- weighted.mean(first_species$ppmr, w = first_species$prey_weight_g, na.rm = TRUE)
stan_dev <- sd(first_species$ppmr, na.rm = TRUE)
#make standard deviation weighted by prey biomass
print(paste(name, av, stan_dev))
}
## [1] "Herring 50043.3236503726 1685614.1037404"
## [1] "Sprat 314.468174204298 76533.6284139077"
## [1] "Cod 301.177621636124 29070.1334453536"
## [1] "Haddock 5001.90702680167 118012.525310239"
## [1] "Whiting 764.489064933461 38072.4144664675"
## [1] "Blue Whiting 1143.88860358898 199775.200923604"
## [1] "Norway Pout 14672.4603655789 8342.95403836346"
## [1] "Poor Cod 5372.26031134847 5823.23144198288"
## [1] "European Hake 104.672112193411 286.507016127052"
## [1] "Monkfish 42.6935520833611 41.1185929915381"
## [1] "Horse Mackerel 5573.93618730612 228014.823524904"
## [1] "Mackerel 66699.6209429561 1733560.9318409"
## [1] "Common Dab 118.754812650074 46037.8604886127"
## [1] "Plaice 660.609256857542 52765.9581443932"
## [1] "Megrim 45.1156822311388 1264.5816834284"
## [1] "Sole 1806.38552734919 5218.83079841897"
## [1] "Boarfish NaN NA"
Looking for the most common PPMR for each individual species.
A graph of the weighted ppmr for each species against the biomass density of the prey. Prints the mean ppmr, as weighted by prey biomass.
#Separated into individual plots for each predator species -> using facet_wrap for the variable (pred_species)
ggplot(data = renamed_df, aes(x=log(ppmr)), group=1) +
labs(title = "Scatter plot: log(PPMR) v. number density of prey", x="log(PPMR)", y="Number density of prey") +
facet_wrap(~renamed_df$pred_species, scale="free_y") +
theme(strip.text = element_text(size = 5)) +
geom_density(aes(weight = no._prey_per_stmch), colour="red")
for (i in 1:length(species_list)){
name <- species_list[i]
first_species <- renamed_df %>%
filter(pred_species == fixed(name))
ggplot(data = first_species, aes(x=log(ppmr)), group=1) +
labs(title = name, x="log(PPMR)", y="Number density of prey") +
geom_density(aes(weight = no._prey_per_stmch), colour="red") +
theme(plot.title = element_text(size=15))
av <- weighted.mean(first_species$ppmr, w = first_species$no._prey_per_stmch, na.rm = TRUE)
stan_dev <- sd(first_species$ppmr, na.rm = TRUE)
print(paste(name, av, stan_dev))
}
## [1] "Herring 728920.024262343 1685614.1037404"
## [1] "Sprat 5525.57476306736 76533.6284139077"
## [1] "Cod 6812.96612927601 29070.1334453536"
## [1] "Haddock 135609.502299352 118012.525310239"
## [1] "Whiting 91609.7353036565 38072.4144664675"
## [1] "Blue Whiting 11611.1739316422 199775.200923604"
## [1] "Norway Pout 24335.9141717664 8342.95403836346"
## [1] "Poor Cod 18259.7873126531 5823.23144198288"
## [1] "European Hake 119.965774012283 286.507016127052"
## [1] "Monkfish 64.8150435811493 41.1185929915381"
## [1] "Horse Mackerel 85689.6709439899 228014.823524904"
## [1] "Mackerel 2026114.28738012 1733560.9318409"
## [1] "Common Dab 3811.53934621726 46037.8604886127"
## [1] "Plaice 3759.25979204793 52765.9581443932"
## [1] "Megrim 497.947700592639 1264.5816834284"
## [1] "Sole 9871.31755486131 5218.83079841897"
## [1] "Boarfish NaN NA"
Looking for the most common PPMR for each individual species.
A graph of the weighted ppmr for each species against the number density of the prey. Prints the mean ppmr, as weighted by number of prey.
first_species <- renamed_df %>% filter(pred_species == fixed("Herring"))
#separate data set of a single species
print(ggplot(data = first_species, aes(x=log(ppmr)), group=1) +
labs(title = "Herring, weighted by prey biomass", x="log(PPMR)", y="Biomass density of observations") +
geom_density(aes(weight = prey_weight_g), colour="red") +
theme(plot.title = element_text(size=15)))
av <- weighted.mean(first_species$ppmr, w = first_species$prey_weight_g, na.rm = TRUE)
stan_dev <- sd(first_species$ppmr, na.rm = TRUE)
print(paste("ave PPMR weighted by prey biomass:", av))
## [1] "ave PPMR weighted by prey biomass: 50043.3236503726"
print(paste("standard deviation:", stan_dev))
## [1] "standard deviation: 1685614.1037404"
print(ggplot(data = first_species, aes(x=log(ppmr)), group=1) +
labs(title = "Herring, weighted by no. of prey", x="log(PPMR)", y="No. density of observations") +
geom_density(aes(weight = no._prey_per_stmch), colour="red") +
theme(plot.title = element_text(size=15)))
av <- weighted.mean(first_species$ppmr, w = first_species$no._prey_per_stmch, na.rm = TRUE)
stan_dev <- sd(first_species$ppmr, na.rm = TRUE)
print(paste("ave PPMR weighted by no. of prey:", av))
## [1] "ave PPMR weighted by no. of prey: 728920.024262343"
print(paste("standard deviation:", stan_dev))
## [1] "standard deviation: 1685614.1037404"
ggplot(data = renamed_df, aes(indiv_prey_weight, no._prey_per_stmch)) +
labs(title = "prey weight v. number of prey per stomach", x="prey weight (g)", y="No. of prey per predator stomach") +
geom_point(size=0.75)
ggplot(data = renamed_df, aes(log(indiv_prey_weight), no._prey_per_stmch)) +
labs(title = "log(prey weight) v. number of prey per predator stomach", x="log(prey weight)", y="No. of prey") +
geom_point(size=0.5)
#Some interesting results --> introduce colours to show ships
renamed_df$'haul_id_short' <- gsub("\\-.*", "", renamed_df$'haul_id')
#rename haul_id values -> separate by ship names (e.g. CLYDE) rather than complete id (e.g. CLYDE-1935-6)
#separated by ship names
ggplot (data = renamed_df, aes(x=log(indiv_prey_weight), y=no._prey_per_stmch)) +
labs(title = "log(prey weight) v. number of prey per stomach", x="log(prey weight)", y="No. prey per stomach") + geom_point(size=.1, colour="red") +
facet_wrap(~haul_id_short, scale="free_y") +
theme(strip.text = element_text(size = 5))
Playing around with data to see any specific correlations; what is the distribution of the weight of prey recorded.
ggplot (data = renamed_df, aes(indiv_prey_weight, pred_weight_g)) +
geom_point(size=0.5) +
labs(title = "Predator v. prey mass plot", x="Prey mass (g)", y="Predator mass (g)")
#mass since measured in g
ggplot(data = renamed_df, aes(log(indiv_prey_weight), log(pred_weight_g))) +
geom_point(size=0.5) +
labs(title = "log(Predator mass) v. log(prey mass) plot", x="log(Prey mass)", y="log(Predator mass)") +
stat_smooth (method='lm', se=FALSE)
## `geom_smooth()` using formula 'y ~ x'
#slope <- coef(lm(log(renamed_df$pred_weight_g)~log(renamed_df$indiv_prey_weight)))
#print(paste("slope of the log(pred) v. log(prey) line of best fit:", slope))
#second part is intercept -> how to separate?
ggplot(data = renamed_df, aes(log(indiv_prey_weight), log(pred_weight_g))) +
labs(title = "log(pred. mass) v. log(prey mass) separated by predator species", x="log(prey mass)", y="log(pred. mass)") +
geom_point(size=0.2, colour="red") +
facet_wrap(~pred_species, scale="free_y") +
theme(strip.text = element_text(size = 2))
1. Prey weight v. predator weight -> attempting to find a link
between the predator mass and the prey mass
2. log(prey weight) v. log(pred. weight) -> using log() to see
proportionality of the axes, slope of added line should = PPMR
3. Looking to find correlation between the masses for each individual
species; the slope should intersect the y-axis at 0, else our idea for
PPMR calculation (pred mass is prop. to prey mass) is incorrect
ggplot(data=renamed_df, aes(log(pred_weight_g), log(ppmr))) +
geom_point(size=0.5) +
labs(title = "log(pred mass) v. log(ppmr) plot", x="log(Pred mass)", y="log(PPMR)") +
stat_smooth (method='lm', se=FALSE)
## `geom_smooth()` using formula 'y ~ x'
slope2 <- coef(lm(log(renamed_df$ppmr)~log(renamed_df$pred_weight_g)))
print(paste("slope of the log(ppmr) v. log(pred_weight) line of best fit:", slope2))
## [1] "slope of the log(ppmr) v. log(pred_weight) line of best fit: 5.14712740503257"
## [2] "slope of the log(ppmr) v. log(pred_weight) line of best fit: 0.312483173844018"
#slope of the above plot
ggplot(data=renamed_df, aes(log(pred_weight_g), log(ppmr))) +
geom_point(size=0.5) +
labs(title = "log(pred mass) v. log(ppmr) plot", x="log(Pred mass)", y="log(PPMR)") + stat_smooth (method='lm', se=FALSE) +
facet_wrap(~pred_species, scale="free_y") +
stat_smooth(method='lm', se=FALSE)
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'
species_df <- renamed_df %>% filter(pred_species == fixed("Poor Cod"))
ggplot(data=species_df, aes(log(pred_weight_g), log(ppmr))) +
geom_point(size=0.5) +
labs(title = "log(pred mass) v. log(ppmr) plot: Poor Cod", x="log(Pred mass)", y="log(PPMR)") + stat_smooth (method='lm', se=FALSE) +
facet_wrap(~pred_species, scale="free_y") +
stat_smooth(method='lm', se=FALSE)
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'
species_slope <- coef(lm(log(species_df$ppmr)~log(species_df$pred_weight_g)))
print(paste("slope of the log(ppmr) v. log(pred_weight) line of best fit:", species_slope))
## [1] "slope of the log(ppmr) v. log(pred_weight) line of best fit: 4.92577224648673"
## [2] "slope of the log(ppmr) v. log(pred_weight) line of best fit: 0.147542734177193"
#for (i in 1:length(species_list)){
# name <- species_list[i]
#first_species <- renamed_df %>% filter(pred_species == fixed(name))
#grad <- coef(lm(log(first_species$ppmr)~log(first_species$pred_weight_g)))
#print(paste(name, grad))
#}
log(pred mass) v. log(ppmr) -> is pred. mass related to ppmr?
We want them to not be proportional (i.e. slope = 0).
CHECK: IS THIS NO. OF POINTS RECORDED OR NO. POINTS*NO. PREY PER STOMACH